home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / pdf2dsc.ps < prev    next >
Text File  |  2003-01-03  |  5KB  |  155 lines

  1. %    Copyright (C) 1994, 1995, 1996, 1997, 1998 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % pdf2dsc.ps
  7. % read pdf file and produce DSC "index" file.
  8. %
  9. % Input  file is named PDFname
  10. % Output file is named DSCname
  11. %
  12. % Run using:
  13. %  gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
  14. % Then display the PDF file with
  15. %  gs tempfilename
  16. %
  17. % Modified by Geoff Keating <geoffk@ozemail.com.au> 21/12/98:
  18. %    Add DocumentMedia, PageMedia comments
  19. %    Use inherited BoundingBox and Orientation
  20. %    Reformat, add new macro 'puts', generally clean up
  21. % Modified by Johannes Plass <plass@dipmza.physik.uni-mainz.de> 1996-11-05:
  22. %    Adds BoundingBox and Orientation if available.
  23. % Modified by rjl/lpd 9/19/96
  24. %    Updates for compatibility with modified pdf_*.ps code for handling
  25. %      page ranges (i.e., partial files) better.
  26. % Modified by Geoff Keating <Geoff.Keating@anu.edu.au> 7/3/96:
  27. %    include Title and CreationDate DSC comments (these are displayed by
  28. %      Ghostview);
  29. %    reduce the size of typical output files by a factor of about 3.
  30. % Modified by L. Peter Deutsch 3/18/96:
  31. %    Removes unnecessary and error-prone code duplicated from pdf_main.ps
  32. % Modified by L. Peter Deutsch for GS 3.33
  33. % Originally by Russell Lang  1995-04-26
  34.  
  35. /DSCfile DSCname (w) file def
  36. systemdict /.setsafe known { .setsafe } if
  37.  
  38. /puts { DSCfile exch writestring } bind def
  39. /DSCstring 255 string def
  40. /MediaTypes 10 dict def
  41.  
  42. % (str1) (str2)  concatstr  (str1str2)
  43. /concatstr {
  44.   2 copy length exch length add string
  45.   dup dup 5 2 roll copy length
  46. % stack: newstring newstring str2 str1-length
  47.   exch putinterval
  48. } bind def
  49.  
  50.    GS_PDF_ProcSet begin
  51.    pdfdict begin
  52.    PDFname (r) file
  53.    pdfopen begin
  54.    /FirstPage where { pop } { /FirstPage 1 def } ifelse
  55.    /LastPage where { pop } { /LastPage pdfpagecount def } ifelse
  56.  
  57. % scan through for media sizes, keep them in the dictionary
  58.    FirstPage 1 LastPage {
  59.       pdfgetpage /MediaBox pget pop   % MediaBox is a required attribute
  60.       aload pop 
  61.       3 -1 roll sub 3 1 roll exch sub exch
  62.       2 array astore 
  63.       aload 3 1 roll 10 string cvs exch 10 string cvs
  64.       (x) exch concatstr concatstr cvn
  65.       MediaTypes 3 1 roll exch put
  66.    } for
  67.  
  68. % write header and prolog
  69.    (%!PS-Adobe-3.0\n) puts
  70.    Trailer /Info knownoget
  71.     {
  72.       dup /Title knownoget
  73.        {
  74.          (%%Title: ) puts
  75.          DSCfile exch write==
  76.        }
  77.       if
  78.       /CreationDate knownoget
  79.        {
  80.          (%%CreationDate: ) puts
  81.          DSCfile exch write==
  82.        }
  83.       if
  84.     }
  85.    if
  86.    % This is really supposed to be sorted by frequency of usage...
  87.    (%%DocumentMedia: )
  88.    MediaTypes { 
  89.       exch pop
  90.       1 index puts
  91.       (y) puts dup 1 get DSCstring cvs puts
  92.       (x) puts dup 0 get DSCstring cvs puts 
  93.       ( ) puts dup 0 get DSCstring cvs puts
  94.       ( ) puts 1 get DSCstring cvs puts 
  95.       ( 70 white ()\n) puts
  96.       pop (%%+ )
  97.    } forall
  98.    pop
  99.  
  100.    (%%Pages: ) puts
  101.    LastPage FirstPage sub 1 add DSCstring cvs puts
  102.    (\n%%EndComments\n) puts
  103.    (%%BeginProlog\n) puts
  104.    (/Page null def\n/Page# 0 def\n/PDFSave null def\n) puts
  105.    (/DSCPageCount 0 def\n) puts
  106.    (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) puts
  107.    (GS_PDF_ProcSet begin\npdfdict begin\n) puts
  108.    (%%EndProlog\n) puts
  109.    (%%BeginSetup\n) puts
  110.    DSCfile PDFname write==only
  111.    ( \(r\) file pdfopen begin\n) puts
  112.    (%%EndSetup\n) puts
  113.    % process each page
  114.    FirstPage 1 LastPage {
  115.        (%%Page: ) puts
  116.        dup DSCstring cvs puts
  117.        ( ) puts
  118.        dup DSCstring cvs puts
  119.        (\n) puts
  120.  
  121.        dup pdfgetpage
  122.        dup /MediaBox pget pop
  123.          (%%PageMedia: y) puts
  124.      aload pop 3 -1 roll sub DSCstring cvs puts
  125.      (x) puts exch sub DSCstring cvs puts
  126.      (\n) puts
  127.        dup /CropBox pget {
  128.          (%%PageBoundingBox: ) puts
  129.          {DSCfile exch write=only ( ) puts} forall
  130.          (\n) puts
  131.        } if
  132.        /Rotate pget {
  133.          (%%PageOrientation: ) puts
  134.          90 div cvi 4 mod dup 0 lt {4 add} if
  135.          [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get puts
  136.          (\n) puts
  137.        } if
  138.  
  139.        DSCfile exch DSCstring cvs writestring
  140.        ( DoPDFPage\n) puts
  141.     } for
  142.    currentdict pdfclose
  143.    end
  144.    end
  145.    end
  146. % write trailer
  147. (%%Trailer\n) puts
  148. (currentdict pdfclose\nend\nend\nend\n) puts
  149. (%%EOF\n) puts
  150. % close output file and exit
  151. DSCfile closefile
  152. quit
  153. % end of pdf2dsc.ps
  154.